from google.appengine.ext import webapp
from models.Users import *
from models.Authentication import *

# Called to get the users own image for the profile picture
class Image(webapp.RequestHandler):
    def get(self):
        # get current logged in user
        user = get_current_user(self.request)
       
        # return users avatar else return a default one
        if user.avatar:
            self.response.headers['Content-Type'] = "image/png"
            self.response.out.write(user.avatar)
        else:
            self.redirect('/public/images/defaultuser.png')

# Called to the avatar of another user
class ProfileImage(webapp.RequestHandler):
    def get(self, userID):
        # get requested user
        user = get_current_user(self.request)
        # return their avatar or default one
        if user.avatar:
            self.response.headers['Content-Type'] = "image/png"
            self.response.out.write(user.avatar)
        else:
            self.redirect('/public/images/defaultuser.png')
